package Test;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MYJFrame2 extends JFrame implements MouseListener {

    JButton jbt1=new JButton("按钮一");

    public MYJFrame2() {
        //        //新建界面
//        JFrame jFrame=new JFrame();
        //设置界面宽高
        this.setSize(600,600);
        //设置界面标题
        this.setTitle("事件演示");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置关闭模式
        this.setDefaultCloseOperation(3);
        //取消默认的居中放置
        this.setLayout(null);


        //设置大小，位置
        jbt1.setBounds(0,0,100,100);
        //给按钮添加动作监听
        jbt1.addMouseListener(this);

        //添加到界面中
        this.getContentPane().add(jbt1);
        //显示界面
        this.setVisible(true);

    }


    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("单击");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按住不松");

    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("松开");

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("划入");

    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("划出");

    }
}
